package generic;

import java.util.ArrayList;

/**
 * @author 15594
 */
public class User<T> {
   private int id ;
   private String name;
   private T t;

    public User() {
    }

    public User(int id, String name, T t) {
        this.id = id;
        this.name = name;
        this.t = t;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", t=" + t +
                '}';
    }
}

class  Test{
    public static void main(String[] args) {
        //如果定义了泛型，不指定泛，则默认为object。
        User user = new User(1,"lihua",new Object());

        System.out.println(user);
        User<String> user1 = new User<>(2,"xiaomin","你好");
        System.out.println(user1);

    }
}

/*
 * 1、继承泛型类——指明父类的类型，那么子类也就确定了
 * */
class User1 extends User<Integer>{
    User1(){
        super(1,"lihua",1);
        System.out.println(super.toString());
    }

}
class Test1{
    public static void main(String[] args) {
        User1 user1 = new User1();
        user1.toString();
    }
}

/*
 * 2、继承泛型类——不指明父类的类型
 * */
class User2<T> extends User<T>{
    private int id ;
    private String name;
    private T t;

    User2(){

    }
    User2(int id,String name,T t){
        this.id = id;
        this.name = name;
        this.t = t;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public void setId(int id) {
        this.id = id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public T getT() {
        return t;
    }

    @Override
    public void setT(T t) {
        this.t = t;
    }

    @Override
    public String toString() {
        return "User2{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", t=" + t +
                '}';
    }
}
class Test2{
    public static void main(String[] args) {
        User2<String> user2 = new User2<>(1,"lihua","1");
        System.out.println(user2);

    }
}